package org.输入输出练习;

import java.util.Scanner;

/**
 * @Auther: qingle
 * @Date: 2024/8/19-2:56
 * @Description:
 * 给定一个n 行  m 列的二维正整数数组  a ，第i 行第  j 列元素的值为
 * ai,j 。请你求出数组元素之和。
 *
 * @version: 1.0
 */
public class PIO9_多组_二维数组_T组形式 {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while(t-- > 0) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			long sum = 0;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					int a = scanner.nextInt();
					sum += a;
				}
			}
			System.out.println(sum);
		}
	}
}
